function $(o) {
	if (!o) {
		return null;
	}
	var ele;
	if (typeof o == "string") {
		ele = document.getElementById(o);
	} else {
		ele = o;
	}
	return ele;
}
String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
 }
String.prototype.replaceAll = function(s1, s2) {
	return this.replace(new RegExp(s1, 'gm'), s2);
}
var CommonUtil = {
	transDigit : function(s) {
		if (CommonUtil.isNull(s))
			return "";
		s = s.replaceAll(",", "");
		if (/[^0-9\.]/.test(s))
			return s;

		s = s.replace(/^(\d*)$/, "$1.");
		s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
		s = s.replace(".", ",");
		var re = /(\d)(\d{3},)/;
		while (re.test(s))
			s = s.replace(re, "$1,$2");
		s = s.replace(/,(\d\d)$/, ".$1");
		s = s.replace(/^\./, "0.")
		return s.replace(".00", "")
	},
	on : function(target, type, func) {
		if (target.addEventListener)
			target.addEventListener(type, func, false);
		else if (target.attachEvent) {
			target.attachEvent("on" + type, func);
		} else
			target["on" + type] = func;
	},
	callback : function(resp, fn) {
		if (fn)
			fn(Ext.util.JSON.decode(resp.responseText));
	},
	toJsonObj : function(jsonText) {
		return Ext.util.JSON.decode(jsonText);
	},
	toJsonText : function(jsonObj) {
		return Ext.util.JSON.encode(jsonObj);
	},
	isNotNull : function(o) {
		return !CommonUtil.isNull(o);
	},
	isNull : function(o) {
		var retb = (typeof(o) == "undefined")|| (typeof (o) == "object" && o == null)|| (typeof (o) == "string" && o.trim().length == 0);
		return retb;
	},
	toInt : function(str) {
		return parseInt(str, 10);
	},
	toFloat : function(v) {
		var rv = parseFloat(v);
		if (isNaN(rv))
			return 0;
		else
			return parseFloat(rv.toFixed(4));
	},
	addTab : function(title, url) {
		window.top.Home.addTabPanel(title, url);
	},
	apply : function(template, values) {
		try {
			var re = /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g;
			var retStr = template.replace(re, function(m, m1) {
				var v = values[m1];
				if (v === undefined)
					v = "";
				return v;
			});

			return retStr.replace(new RegExp("value= ", 'gm'), "").replace(
					new RegExp("title= ", 'gm'), "");
		} catch (e) {
			return "Error 01." + e;
		}
	},
	createWindow : function(config, url) {
		if (CommonUtil.isNull(url))
			url = Config.path + '/web/def/def.jsp';
		if (typeof config == "string") {
			config = {
				title : config
			};
		}
		var win = new Ext.Window(Ext.applyIf(config || {}, {
			title : '/web/def/def.jsp',
			width : 1024,
			height : 600,
			closeAction : 'close',
			maximizable : true,
			minimizable : false,
			minimized : true,
			autoScroll : false,
			bodyBorder : false,
			draggable : true,
			isTopContainer : true,
			modal : false,
			resizable : true,
			contentEl : Ext.DomHelper.append(document.body, {
				tag : 'iframe',
				bodyBorder : false,
				style : "border 0px none;scrollbar:true;frameborder:0",
				src : url,
				height : "100%",
				width : "100%"
			})
		}));
		win.show();
		top.currentWin = win;
		return win;
	},
	getHtml : function(url) {
		var html_ = "";
		Ext.Ajax.request({
			async : false,
			url : url,
			method : 'GET',
			headers : Config.headers,
			callback : function(options, success, response) {
				html_ = response.responseText;
			}
		});
		return html_;
	},
	getPageScroll : function(){
		var yScroll=0;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {
			yScroll = document.body.scrollTop;
		}	 
		return yScroll;
	}
}
Date.prototype.Format = function(formatStr) {
	var Week = [ '日', '一', '二', '三', '四', '五', '六' ];
	return formatStr.replace(/yyyy|YYYY/, this.getFullYear()).replace(
			/yy|YY/,
			(this.getYear() % 100) > 9 ? (this.getYear() % 100).toString()
					: '0' + (this.getYear() % 100)).replace(
			/MM/,
			(this.getMonth() + 1) > 9 ? (this.getMonth() + 1).toString() : '0'
					+ (this.getMonth() + 1)).replace(/M/g,
			(this.getMonth() + 1)).replace(/w|W/g, Week[this.getDay()])
			.replace(
					/dd|DD/,
					this.getDate() > 9 ? this.getDate().toString() : '0'
							+ this.getDate()).replace(/d|D/g, this.getDate());
};